package easy;

public class Day09 {
    public static void main(String[] args) {
        String haystack = "hello", needle = "ll";

        System.out.println(strStr2(haystack, needle));
    }

    public static int strStr2(String haystack, String needle) {
        int H = haystack.length(), N = needle.length();
        if (N > H) return -1;
        if (N == 0) return 0;
        for (int index = 0; index < H - N + 1; index++) {
            String string = haystack.substring(index, index + N);
            if (string.equals(needle)) return index;
        }
        return -1;

    }

    public static int strStr(String haystack, String needle) {
        if (needle.equals("")) return 0;
        return haystack.indexOf(needle);
    }
}
